package org.genew.squadra.xml.common;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.genew.squadra.xml.model.Parsing;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ParserIMG {
	
	Parsing ps;
	Handler eh;

	
	public ParserIMG() {
		ps = new Parsing();
		eh = new Handler();
	
	}

	public Parsing parseIMG(File current){
		try {
			File file = current;
			SAXParserFactory f = SAXParserFactory.newInstance();
			SAXParser p;
			p = f.newSAXParser();
			p.parse(file, eh);
			ps.setUrl(eh.getUrlImage());
			ps.setFileName(current.getName());
			ps.setnImage(eh.getnImage());	
		} catch (ParserConfigurationException | SAXException | IOException e) {
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
		return ps;
	}

}
